/*
 * @lc app=leetcode.cn id=119 lang=javascript
 *
 * [119] 杨辉三角 II
 */

// @lc code=start
/**
 * @param {number} rowIndex
 * @return {number[]}
 */

var getRow = function(rowIndex) {
  let n = rowIndex;
  let f = new Array(2);
  for (let i = 0; i < 2; i++) f[i] = new Array(n);

  f[0][0] = f[1][0] = f[1][1] = 1;
  for (let i = 2; i <= n; i++) {
    let ind = i & 1;
    let pre_ind = (ind + 1) & 1;
    f[ind][0] = f[ind][i] = 1;
    for (let j = 1; j <= i - 1; j++) {
      f[ind][j] = f[pre_ind][j-1] + f[pre_ind][j];
    }
  }
  return f[n & 1];
};
// @lc code=end

